package kr.ac.kaist.vrowser.data;

import java.util.ArrayList;
import android.util.Log;

public class BrowsingHistory {
	
	private ArrayList<String> browsingHistories;
	private int current;
	private boolean refresh;
	static final String tag = "history";

	public BrowsingHistory(){
		browsingHistories = new ArrayList<String>();
		current = -1;
		refresh = false;
	}
	
	public void addHistory(String url){
		if(refresh){
			while(browsingHistories.size()-1>current){
				Log.i("remove history", current+"");
				Log.i("remove history", browsingHistories.get(current+1));
				browsingHistories.remove(current+1);
			}
			refresh = false;
		}
		browsingHistories.add(url);
		current++;
		Log.i(tag, current+browsingHistories.toString());
	}
	
	public String goBack(){
		if (current<=0) {
			current = -1;
			return null;
		} else {
			refresh = true;
			current--;
			Log.i(tag, current+browsingHistories.toString());
			return browsingHistories.get(current);
		}
	}
	
	public String getCurrentURL(){
		if (0 <= current && current < browsingHistories.size())
			return browsingHistories.get(current);
		else
			return null;
	}
	
	public String goForward(){
		if (current==browsingHistories.size()-1){
			return null;
		} else {
			refresh = true;
			current++;
			Log.i(tag, current+browsingHistories.toString());
			return browsingHistories.get(current);
		}
	}
}
